import mapEditor from '@/components/mapEditor/mapEditor.vue'
import mapFolder from '@/components/mapFolder/mapFolder.vue'
import mapOthers from '@/components/mapOthers/mapOthers.vue'

export default {
  name: 'mapManage',
  components: {
    mapEditor,
    mapFolder,
    mapOthers
  },
  data () {
    return {
      isLoading: true,
      
      // 统一进行信息统筹管理
      // 地图文件数据列表(文件信息), 需求: map-layout, 修改: map-layout
      maps: [],
      // 选中的地图文件(文件信息), 需求: map-layout/map-editor, 修改: map-layout
      selectedId: null,
      // 打开地图的信息(详细信息), 需求: map-editor/map-others, 修改: map-editor/map-others
      mapData: null,
      // 地图被选中的图块(index)，需求: map-editor/map-others, 修改: map-editor
      selectedItem: null,
      // 被选中的预备资源
      selectedObj: null,
    }
  },
  methods: {
    mapFolderChangeHandler (list, selectedId, eventName) {
      if (eventName === 'get') {
        // 检测到初始化成功
        this.isLoading = false
      }
      if (eventName === 'delete') {
        // 删除的文件是当前打开的文件时，关闭
        if (this.mapData && this.selectedId === this.mapData.id) {
          this.$refs.mapEditor.closeMap()
        }
      }

      this.maps = list
      this.selectedId = selectedId
      // console.log(this.mapSelected)
    },
    
    mapDetailChangeHandler (mapData, selectedItem, eventName, preparations) {
      this.mapData = mapData
      this.selectedItem = selectedItem
      if (eventName === 'open' || eventName === 'close') {
        // 打开和关闭地图时，保存状态初始化
        this.$refs.mapEditor.initSave()
      }
      if (eventName === 'set') {
        // 修改地图状态时，提示保存
        this.$refs.mapEditor.notSave()
      }
      
    },
    
    selectedHandler (obj) {
      this.selectedObj = obj
      // console.log(obj)
    }
  }
}